<?php
if(isset($_POST['question']) && isset($_POST['publish_date'])){
    $question = $_POST['question'];
    $publish_date = $_POST['publish_date'];
    
    $lines = file("publist.txt");
    $c = count($lines)-1;
    $r = 0;
	for($i=$c;$i>=0;$i--) {
		if(strpos($lines[$i],$publish_date) === 0) $r++;
	}
	if($r>0) $publish_date = $publish_date . "-" . $r;

    file_put_contents("publist.txt", $publish_date . "\n", FILE_APPEND);
    file_put_contents( "pub/" . $publish_date . ".html", $question);
    echo "ok";
} else {
    echo "error";
}
?>